package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.mapper.UserMapper;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ImportResource;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yj
 * @description
 * @date
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;

    @Override
    public User login(String tel) {
        return userMapper.selectOne(tel);
    }

    @Override
    public User register(User user) {
        int i = userMapper.insertUser(user);
        return user;
    }

    @Override
    public PageInfo<User> findAll(int p,int size) {
        PageHelper.startPage(p,size);
        List<User> list = userMapper.selectAll();
        PageInfo<User> userPageInfo = new PageInfo<>(list);
        return userPageInfo;
    }

    @Override
    public User updateUser(User user) {
        int i = userMapper.updateUser(user);
        return user;
    }

    @Override
    public Boolean deleteUser(int id) {
        int i = userMapper.deleteUser(id);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public User addUser(User user) {
        int i = userMapper.insertUser(user);
        return user;
    }

}
